"use strict";

/*
 * MikoPBX - free phone system for small business
 * Copyright © 2017-2023 Alexey Portnov and Nikolay Beketov
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program.
 * If not, see <https://www.gnu.org/licenses/>.
 */

/* global ace, PbxApi */

/**
 * Object for managing system diagnostic system information view.
 *
 * @module systemDiagnosticSysyinfo
 */
var systemDiagnosticSysyinfo = {
  viewer: '',
  receivedInfo: false,
  $tabMenuItems: $('#system-diagnostic-menu .item'),
  $dimmer: $('#sysinfo-dimmer'),
  $contentFiled: $('#sysinfo-content-readonly'),

  /**
   * Initializes the system diagnostic system information view.
   */
  initialize: function initialize() {
    var aceHeight = window.innerHeight - 300; // Set the minimum height of the system information container

    systemDiagnosticSysyinfo.$dimmer.closest('div').css('min-height', "".concat(aceHeight, "px")); // Hide the content field initially

    systemDiagnosticSysyinfo.$contentFiled.hide(); // Event listener for tab menu items click

    systemDiagnosticSysyinfo.$tabMenuItems.on('click', function (e) {
      if ($(e.target).attr('data-tab') === 'show-sysinfo' && systemDiagnosticSysyinfo.receivedInfo === false) {
        systemDiagnosticSysyinfo.initializeAce();
        PbxApi.SysInfoGetInfo(systemDiagnosticSysyinfo.cbUpdateSysinfoText);
      }
    });
  },

  /**
   * Initializes the ACE editor for system information content.
   */
  initializeAce: function initializeAce() {
    var aceHeight = window.innerHeight - 300;
    var rowsCount = Math.round(aceHeight / 16.3); // Set the minimum height of the ACE editor

    $(window).load(function () {
      $('.log-content-readonly').css('min-height', "".concat(aceHeight, "px"));
    });

    var IniMode = ace.require('ace/mode/julia').Mode;

    systemDiagnosticSysyinfo.viewer = ace.edit('sysinfo-content-readonly');
    systemDiagnosticSysyinfo.viewer.session.setMode(new IniMode());
    systemDiagnosticSysyinfo.viewer.setTheme('ace/theme/monokai');
    systemDiagnosticSysyinfo.viewer.resize();
    systemDiagnosticSysyinfo.viewer.renderer.setShowGutter(false);
    systemDiagnosticSysyinfo.viewer.setOptions({
      showLineNumbers: false,
      showPrintMargin: false,
      readOnly: true,
      maxLines: rowsCount
    });
  },

  /**
   * Callback for updating the system information view.
   * @param data - The system information data.
   */
  cbUpdateSysinfoText: function cbUpdateSysinfoText(data) {
    systemDiagnosticSysyinfo.$dimmer.removeClass('active');
    systemDiagnosticSysyinfo.viewer.getSession().setValue(data.content);
    systemDiagnosticSysyinfo.receivedInfo = true;
    systemDiagnosticSysyinfo.$contentFiled.show();
  }
}; // When the document is ready, initialize the system information view

$(document).ready(function () {
  systemDiagnosticSysyinfo.initialize();
});
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9TeXN0ZW1EaWFnbm9zdGljL3N5c3RlbS1kaWFnbm9zdGljLWluZGV4LXN5c2luZm8uanMiXSwibmFtZXMiOlsic3lzdGVtRGlhZ25vc3RpY1N5c3lpbmZvIiwidmlld2VyIiwicmVjZWl2ZWRJbmZvIiwiJHRhYk1lbnVJdGVtcyIsIiQiLCIkZGltbWVyIiwiJGNvbnRlbnRGaWxlZCIsImluaXRpYWxpemUiLCJhY2VIZWlnaHQiLCJ3aW5kb3ciLCJpbm5lckhlaWdodCIsImNsb3Nlc3QiLCJjc3MiLCJoaWRlIiwib24iLCJlIiwidGFyZ2V0IiwiYXR0ciIsImluaXRpYWxpemVBY2UiLCJQYnhBcGkiLCJTeXNJbmZvR2V0SW5mbyIsImNiVXBkYXRlU3lzaW5mb1RleHQiLCJyb3dzQ291bnQiLCJNYXRoIiwicm91bmQiLCJsb2FkIiwiSW5pTW9kZSIsImFjZSIsInJlcXVpcmUiLCJNb2RlIiwiZWRpdCIsInNlc3Npb24iLC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